import 'http_exceptions.dart';

class HttpResponse {
  late bool ok;
  var data;
  var token;
  HttpException? error;

  HttpResponse.success(this.data, this.token) {
    this.ok = true;
  }

  /// 客户端请求失败
  HttpResponse.failure({String? errorMsg, int? errorCode}) {
    this.error = BadRequestException(message: errorMsg, code: errorCode);
    this.ok = false;
  }

  HttpResponse.failureFormResponse({dynamic data}) {
    this.error = BadResponseException(data);
    this.ok = false;
  }

  /// 请求失败
  HttpResponse.failureFromError([HttpException? error]) {
    this.error = error ?? UnknownException();
    this.ok = false;
  }
}
